i will write a program with function that recursively print from 1 to 2^n
for example i give number 3 to pragram and it will be print 1 2 4 8
sorry for my bad english, plz help me on this program
i will write a program with function that recursively print from 1 to 2^n
for example i give number 3 to pragram and it will be print 1 2 4 8
sorry for my bad english, plz help me on this program
Well....
Code:void foo ( int depth ) { if ( depth >= 0 ) { foo(depth-1); } }
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
but this not works
That's because it's an "idea", not an "answer" you can just run back to teacher with, without thinking about it.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
i know the way of a recursive, but i will know the algorithm of this program, i thinked very much, but i can't
Well, show us what you've tried. Post your code in code tags (read this link), and we'll help you fix whatever problems you're having.
i dont write any code but i thinked about it really
> for example i give number 3 to pragram and it will be print 1 2 4 8
So figure out how to do it using just a simple for loop, then you'll have your answer.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
Well, then just tell your teacher you thought about it and thought up a correct answer. I'm sure s/he will give you a good grade for "thinking about it". You have nothing to lose by trying. It's not like making a mistake will cause your computer to blow up, taking your hands and arms with it. Besides, you might even learn something along the way. Regardless, we sure wont do it for you, so you try something, and post your attempt, and we will help you.
Just in case you come back for help, here's an additional hint. Take Salem's code and add one print statement to it; that's all you need to do. Also, look up the left shift operation.
Bitwise operation - Wikipedia, the free encyclopedia
I you aren't even going to go as far as making an attempt and posting the code then you obviously aren't cut out to be a programmer.
As a programmer you need to be able to push the boundaries, step outside of the box, and try things you haven't tried before. Otherwise you'll never get past "Hello World".
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
i changed to this shape, see that, a[k]'s is true but a[i] is wrong. why?
Code:void baz(int n,int k,int l){ int i,s=1,a[100]; if (n>0){ for(i=0;i<n;i++){ s=s*2;} a[k]=s; printf(" %d ",k); printf("%d ",a[k]); baz(n-1,k-1,l); } else{ printf("%d",k); a[k]=1; for(i=0;i<=l;i++){ printf("%d ",i); printf("%d ",a[i]);} } }
I correct it on my own, the truth code is this:
Code:void baz(int n,int k,int l,int* a){ int i,s=1; if (n>0){ for(i=0;i<n;i++){ s=s*2;} a[k]=s; baz(n-1,k-1,l,a); } else{ a[k]=1; for(i=0;i<=l;i++) printf("%d ",a[i]); } }
but maximum number is 14 when you enter 15 it will be negative 32768, i changed a type to unsigned int but the maximum number is 14 again, how can I up this range?
What compiler are you using...
If it's not going past 16 bits I'm guessing you're using some old DOS version of Turbo C... which has been obsolete for more than a decade.
Grab a newer compiler... Pelles C is a good choice. When you download it spend some time in the help file and learn what's going on before you do any coding... In particular look up the tutorial on making your first project.